1. Technical Field
The present invention provides an improved data processing system and, in particular, provides a method and apparatus for memory management in a data processing system. Still more particularly, the present invention provides an improved functionality within a garbage collector in a data processing system.
2. Description of Related Art
A virtual machine, such as a Java virtual machine (JVM), typically allocates memory for the instantiation of an object from a free memory area called a heap. The allocation and freeing of memory in the heap is usually allocated and freed in set blocks. A single heap exists within a Java virtual machine instance. A separate heap, however, exists for each instance of the Java virtual machine. Since each application is associated with a single instance of a Java virtual machine, two Java applications will not trample or use each other""s heap data. The Java virtual machine has instructions to allocate memory on the heap for a new object but includes no instructions for freeing or deallocating previously allocated memory. Hence, the Java virtual machine is responsible for deciding whether and when to free or deallocate memory occupied by objects that are no longer referenced by a running application. A garbage collector in the Java virtual machine performs garbage collection to reclaim the memory space used by objects that are no longer referenced by an application. The reclaimed memory is then recycled by reallocating the memory space for other objects.
The Java Virtual Machine (JVM) architecture relies heavily on the use of garbage collection as a core part of its memory management strategy. Garbage collection is the name given to the task of: automatically determining which blocks of memory can be freed by marking them as no longer needed by an application when they fall xe2x80x9cout of scopexe2x80x9d during program execution; collecting all of these blocks of memory at periodic intervals; returning them to the heap; and marking the blocks as available for use. This process of xe2x80x9ccollecting the garbagexe2x80x9d must be done skillfully as the garbage collection process, while freeing resources, can itself consume system resources, particularly processor time.
Virtual machine platforms are an evolving computing platform with Java being the most prevalent of these platforms. One of the most touted features of Java is its portability. With the xe2x80x9cwrite once, run anywherexe2x80x9d concept, it is envisioned that a Java application or applet could run on a mainframe computer, and without modification, also run on a hand-held device, a Personal Digital Assistant (PDA), a printer, or some other output device. Obviously, a PDA and a mainframe computer have widely varying computing resources. A Java virtual machine running on each of these platforms may have widely varying amounts of memory or bandwidth at its disposal, and a properly designed JVM should take advantage of the available resources while accomplishing the goal of portability. In order to achieve these goals with respect to memory management, it is desirable to have a single design of a JVM that addresses the common problems of performance and portability.
The exact garbage collection strategy used by a JVM will vary depending on the type of system upon which the JVM is executing. In current JVM implementations, the garbage collector is a xe2x80x9cbuilt-inxe2x80x9d component in the JVM, i.e. different garbage collectors cannot be plugged in for different circumstances. Hence, the deployment of a particular JVM for a particular computer platform usually dictates the garbage collection strategy that will be employed within the JVM.
Many different algorithms have been employed in different garbage collector implementations. These algorithms are typically tailored to the type of environment in which the Java programs are executing. For example, server applications in a multi-user multiprocessor environment tend to have a memory-use profile that differs from a desktop computer environment. Furthermore, embedded-Java devices, such as cell phones, and handheld devices, such as those that use the Microsoft WinCE operating system, have different memory-use profiles.
Maintaining different garbage collectors for different JVMs can be expensive for providers of JVMs. A single garbage collector is designed to implement one particular strategy and cannot be modified xe2x80x9con-the-flyxe2x80x9d to change its strategy, and a single garbage collector is built into each JVM instance depending upon the computer platform on which the JVM executes. Providers of JVMs must then track, service, and support these JVM instances.
Moreover, one cannot guarantee that an installed JVM will have a given level of performance. On any given day, a particular set of garbage collection characteristics, i.e. garbage collection algorithm metrics, will be better for one device but possibly not for another device. For example, a device with a small amount of memory may require a very aggressive garbage collector whereas as a large server with lots of memory may require a relaxed approach. However, if at some later point in time, more memory is added to a device that already has an installed JVM, the garbage collection strategy of the JVM cannot be modified to conform with the larger amount of memory. In another example, a server with an installed JVM may be modified by adding additional processors. In each case, a different JVM would need to be installed with a different type of garbage collection algorithm in order to adapt the performance of the garbage collector to the performance characteristics of the hardware platform. Reinstallation of a complete Java environment may be expensive and time-consuming.
Therefore, it would be advantageous to have an improved method and apparatus for managing memory in a data processing system. It would be particular advantageous to have a method and apparatus for managing memory with an improved garbage collector.
The present invention provides a method, system, and computer-program product for a dynamically adjustable and configurable garbage collector. Values for an environment variable or set of variables or parameters are obtained by the dynamic garbage collector. The variables may be set through user input or upon configuration of a computer platform. The values of the variables may be modified or updated during execution of the garbage collector, which receives or retrieves the newly modified values. The garbage collector then performs memory management functions according to a behavioral algorithm that incorporates the values of the environment variables or parameters or according to a behavioral algorithm that is selected by the environment variable.